1000 גמדים, לכל גמד כובע לבן או שחור. הגמדים צריכים להסתדר בטור שכל הלבנים אחד ליד השני וכל השחורים אחד לידי השני.
אסור לגמדים לדבר אחד עם השני. איך יסתדרו בטור?
תשובות
הוסף תשובה
|
לצפיה בתשובות
אוגוסט 2015
שניים ראשונים יעמדו אחד לישי השני. אם שני הגמדים לבנים או שניהם שחורים הגמד השלישי יעמד בצד ימין או שמאל אם אחד שחור ואחד לבן הגמד יעמוד בינהם. וכך הלאה כל גמד שיגיע יעמוד בין הגמד השחור לגמד הלבן..
1. Videos are represented by a series of picture frames, while the difference between each frame is usually low. An image is described as frame of motion vectors, which describe the movement of pixels from one picture to the next picture in line. An object within the frame is a group of close-by motion vectors which are equal. Assume the frame is represented by one dimensional array of motion vectors most of which are (0,0) find the largest object.
2. Assume video streaming needs to be fast and you would want to utilize all cores. How would you change the program to be multithreaded?
תשובות
הוסף תשובה
|
לצפיה בתשובות
יוני 2015
1. Keep an array of bool for visited/unvisited points. Starting from the upper left point traverse recursively to the right, bottom and left points to search for objects. Once an object is reached, traverse through it (only to points with similar value) and count the points within the object.
Compare number of points to current max sized object and modify max sized object.
2.
Under the given assumption that most of the frame is (0,0), I would use multi threading to scan for
object without splitting into regions of responsibility. Once a thread finds an object he locks all other threads until he completes it's traversal through the object.
In case the assumption is not true, the algorithm would work much similar to a non multi-threading algorithm.
Packets are being sent in arbitrary time.
We have a window time of one second from current time that the program receives.
Lets assume current time is t=10;
packet - t =9.1 packet - t =9.3 packet - t =9.8 ----> packet - t =9.8 packet - t =9.3 packet - t =9.1
We need to make sure that that the packet will be sent in order.
Use set_timer, cancel_timer, now functions to implement func and c_b functions.
Void func(time_t t, void* data)
{
}
void c_b(...) //activated when t time in timer passed. not sure what were the parameters...
{
}
void set_timer(time_t t, FuncType c_b); //set timer, after t time pass c_b is activated
void cancel_timer(); // cancel timer
time_t now(); // get current time